22
class Solution {
    public ListString generateParenthesis(int n) {
        ListString ret = new ArrayList();

        fun(ret, 0, n2, new StringBuilder());
        return ret;
    }

    public void fun(ListString ret, int size, int len, StringBuilder str) {
        if (len == size) {
            if (check(str.toString(), len)) {
                ret.add(str.toString());
            }
            return;
        }
        str.append('(');
        fun(ret, size+1, len, str);
        str.deleteCharAt(size);
        str.append(')');
        fun(ret, size+1, len, str);
        str.deleteCharAt(size);
    }

    public boolean check(String str, int len) {
        int count = 0;
        for (int i = 0; i  len; i++) {
            if (str.charAt(i) == ')') {
                count--;
            } else {
                count++;
            }
            if (count  0) {
                return false;
            }
        }
        if (count != 0) {
            return false;
        }
        return true;
    }
}
写一个函数返回参数二进制中 1 的个数
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int count = 0;
        while (n != 0){
            if ((n & 1) == 1){
                count++;
            }
            n >>>= 1;
        }
        System.out.println(count);
    }
}